package java8._06_使用流收集数据;

import com.google.common.collect.Sets;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class _04_调用MyListCollector {

    @Test
    public void test() {

        List<Integer> collect2 = IntStream.rangeClosed(1, 20)
            .parallel()
            .mapToObj(item -> item)
            .collect(new _03_MyListCollector<>(null));

        System.out.println(collect2);


        Set<Collector.Characteristics> ts = Sets.newHashSet(
            //Collector.Characteristics.UNORDERED,
            Collector.Characteristics.CONCURRENT,
            Collector.Characteristics.IDENTITY_FINISH
        );
        List<Integer> lists = IntStream.rangeClosed(1, 30)
            .parallel()
            .mapToObj(item -> item)
            .sorted()
            .collect(new _03_MyListCollector<>(ts));
        System.out.println(lists);
        System.out.println(lists.size());


        System.out.println("-------------------华丽分割线----------------------");
        Set<Integer> sets = IntStream.rangeClosed(1, 30).mapToObj(item -> item).collect(Collectors.toSet());
        Set<Collector.Characteristics> ts2 = Sets.newHashSet(
            //Collector.Characteristics.UNORDERED
            Collector.Characteristics.CONCURRENT,
            Collector.Characteristics.IDENTITY_FINISH
        );
        List<Integer> lists2 = sets.stream()
            .parallel()
            .skip(2)
            .collect(new _03_MyListCollector<>(ts2));
        System.out.println(lists2);
        System.out.println(lists2.size());

        List<Integer> lists4 = sets.stream()
            .parallel()
            .skip(2)
            .collect(ArrayList::new, List::add, List::addAll);
        System.out.println("-------------------另外で一条，华丽の分割线----------------------");
        System.out.println(lists4);
        System.out.println(lists4.size());
    }

}
